// import data from '@/common/data.js'; //筛选菜单数据
import validator from '@/common/validator'
export default {
	data() {
		return {
			status: 'loadmore',
			// 地域数据
			placeData: null,

			defaultSelected: [],
			filterData: [],
			keyword: null,
			// 记录页数
			page: 1,
			pageSize: 10,
			// 公司的数量
			allCompany: null,
			allData: [],
			allPage: null,
			allSize: null,
			//当前被点击的数据
			currentData: null,
			popupFlag: false,
			chooseObj: {},
			// 判断字符a是否存在
			wordA:null,
			// 判断字符b是否存在
			wordB:null
			// customStyle:{
			// 	"width": "85%"
			// }
		}
	},
	onLoad: function() {
		this.placeData = uni.getStorageSync('filterPlaceData')
		this.getPlaceData()
		//定时器模拟ajax异步请求数据
		this.filterData = []
		// console.log('修改菜单');
		let companyType = uni.getStorageSync('filterCompanyType')

		this.filterData.push({
			name: '地区',
			"type": 'hierarchy',
			"submenu": this.placeData
		})

		// this.filterData.push({
		// 	"name": '类型',
		// 	"type": 'filter',
		// 	"submenu": [{
		// 		"name": "类型",
		// 		"submenu": companyType
		// 	}]
		// })
		this.changeSelected()
		// 查询十条信息显示在页面上
		this.findAchievements()
	},
	methods: {
		refreshArr() {
			if (this.page >= this.allPage) {
				this.status = 'nomore';
				return
			}
			this.status = 'loading';
			this.page = ++this.page;
			setTimeout(() => {
				this.findAchievements()
				if (this.page >= this.allPage) this.status = 'nomore';
				else this.status = 'loading';
			}, 2000)
		},
		getPlaceData() {
			let data = uni.getStorageSync('filterPlaceData')
			this.placeData = data
			this.areaList = []
			let obj = {
				name: '省份',
				value: '省份',
				submenu: [{
					name: "全部",
					value: "全部"
				}]
			}

			data.forEach(item => {
				obj.submenu.push({
					name: item.name,
					value: 'A' + item.name
				})
			})
			this.placeData.unshift(obj)
			this.areaList.push(obj)
			// console.log("this.areaList",this.areaList)
		},

		// 搜索
		searchResult(value) {
			// console.log("____________________",value,this.keyword)
			// 点击搜索  验证不为空后，调用接口
			if (!validator.checkNullValue(this.keyword)) {
				return;
			}
			this.allData = []
			this.page=1
			this.findAchievements()
		},
		// // 查询业绩信息
		findAchievements() {
			let param = {
				
				'page': this.page,
				"pageSize": this.pageSize
			}
			if (this.keyword) {
				param.companyName = this.keyword
			}
			if (this.chooseObj.qualification) {
				param.qualification = this.chooseObj.qualification
			}
			if (this.chooseObj.companyProvince) {
				param.companyProvince = this.chooseObj.companyProvince
			}
			if (this.chooseObj.companyCity) {
				param.companyCity = this.chooseObj.companyCity
			}
			this.status = 'loading';
			this.$app.request({
				// url: this.$baseApp.api.check.findCompanyProjectDetailsListAll,
				url: this.$baseApp.api.dicData.companyProjectDetailsList,
				data: param,
				method: 'GET',
				dataType: 'json',
				success: res => {
					if (res.code == 200) {
						this.allPage = res.data.totalPages
						this.allSize = res.data.totalElements
						if (this.allPage <= 1||res.data.content.length<10) {
							this.status = 'nomore'
						}else{
							this.status =  'loadmore'
						}
						res.data.content.forEach((item) => {
							item.companyBaseInfo = JSON.parse(item.companyBaseInfo)
							//关键字标红
							item.companyBaseInfo.companyProName = validator.joinStr(item
								.companyBaseInfo.companyProName, this.keyword)
							item.companyBidding.forEach((item2, index2) => {
								item2.companyWinningUnitName = validator.joinStr(item2
									.companyWinningUnitName, this.keyword)

							})

						

							this.allData.push(item)

						})

					} else {
						// this.$alert(res.msg);
						this.showTip(res.msg)
					}
				},
				complete: res => {
					uni.stopPullDownRefresh();
					uni.hideLoading();
				}
			});
		},

		//接收菜单结果
		confirm(e) {
			this.indexArr = e.index;
			this.valueArr = e.value;
			// console.log("this.valueArr", this.valueArr)
			// console.log("this.valueArr", this.valueArr)
			this.chooseObj = {}

			this.wordA = this.valueArr[0][1].indexOf('A')
			this.wordB = this.valueArr[0][1].indexOf('B')

			if (this.valueArr[0][1] && this.valueArr[0][1] == 'B市辖区') {
				this.chooseObj.companyProvince = this.valueArr[0][0].slice(1)

			} else {
				if (this.wordA > -1) {
					this.chooseObj.companyProvince = this.valueArr[0][1].slice(1)
				}
				if (this.wordB > -1) {
					this.chooseObj.companyCity = this.valueArr[0][1].slice(1)
				}
				this.wordA = null
				this.wordB = null
			}

			// this.valueArr[1][0].forEach(item => {
			// 	if (this.chooseObj.qualification) {
			// 		this.chooseObj.qualification += ',' + item.code
			// 	} else {
			// 		this.chooseObj.qualification = item.code
			// 	}
			// })

			// console.log("this.chooseObj", this.chooseObj)

			this.allData = []
			this.findAchievements()
		},
		//修改选中项-示例
		changeSelected() {
			//设置选中项
			// 一下的注释是针对测试数据说明结构的意思，具体传入什么数据，要看你自己数据。如果data.js数据有修改，注意defaultSelected也要修改
			//传入defaultSelected的结构不能错，错了就报错运行异常。 不想选中的请传入null

			this.defaultSelected = [];
			this.$nextTick(() => {
				this.defaultSelected = [
					[0, 0], //第0个菜单选中 一级菜单的第6项，二级菜单的第0项，三级菜单的第1项

					// [
					// 	[0],
					// 	[1],
					// 	[1]
					// ] //单选菜单选中 第一个筛选的第0项，第二个筛选的第1项，第三个筛选的第1项
				];
			})
		},
	}
}
